package cn.circle.system.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import cn.circle.system.dao.IOrderInfoDao;
import cn.circle.commom.dao.impl.BaseDaoImpl;
//import cn.circle.commom.model.Apartment;
import cn.circle.system.model.OrderInfo;


@Repository
public class OrderInfoDaoImpl extends BaseDaoImpl<OrderInfo> implements IOrderInfoDao {
  
	@Override
	public  boolean updateStatus(String ids) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer(
				"update OrderInfo s set s.sendStatus=3 where s.orderId ="+ids);
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql.toString());
		return (query.executeUpdate() > 0);
	}
	
	@Override
	public boolean deleteAll(String ids) {
		// TODO Auto-generated method stub

		String hql = "delete OrderInfo s where s.orderId in (" + ids + ") ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		// query.setString(0, ids);
		return (query.executeUpdate() > 0);
	}

	@Override
	public boolean removeAll(String ids) {
		// TODO Auto-generated method stub

		String hql = "update OrderInfo s set s.status = 0 where s.orderId in (" + ids + ") ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return (query.executeUpdate() > 0);

	}

	/*@Override
	public List<Apartment> getDep() {
		// TODO Auto-generated method stub
		String hql = " from Apartment ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return  query.list();
	}*/

	@Override
	public boolean updateAll(OrderInfo c) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer(
				"update OrderInfo s set ");
		
		//拼接修改条件
	/*	if(c.getCommodityInfo().getCommodityId()!= null && !"".equals(c.getCommodityInfo().getCommodityId())){
			hql.append("  s.names = '"+c.getCommodityInfo().getCommodityId()+"' ");
		}
		if(c.getSyscustomer().getCustId() != null && !"".equals(c.getSyscustomer().getCustId())){
			hql.append(" , s.loginName = '"+c.getSyscustomer().getCustId()+"' ");
		}*/

		
		if(c.getOrderNumber() != null && !"".equals(c.getOrderNumber())){
			hql.append(" , s.depId = "+c.getOrderNumber()+" ");
		}
		if(c.getPayPrice() != null && !"".equals(c.getPayPrice())){
			hql.append(" , s.createUserId = "+c.getPayPrice()+" ");
		}
		if(c.getPayStatus() != null ){
			hql.append(" , s.orderCount = '"+c.getPayStatus()+"' ");
		}
		if(c.getPayTime() != null && !"".equals(c.getPayTime())){
			hql.append(" , s.photo = "+c.getPayTime() +" ");
		}
		if(c.getPayWay() != null && !"".equals(c.getPayWay())){
			hql.append(" , s.price = "+c.getPayWay()+" ");
		}
		if(c.getSendStatus() != null && !"".equals(c.getSendStatus())){
			hql.append(" , s.status = "+c.getSendStatus()+" ");
		}
		if(c.getSerialNumber()!= null && !"".equals(c.getSerialNumber() )){
			hql.append(" , s.summary = "+c.getSerialNumber() +" ");
		}
		if(c.getSendStatus()!= null && !"".equals(c.getSendStatus() )){
			hql.append(" , s.sendStatus = "+c.getSendStatus());
		}

		hql.append(" where s.orderId ="+c.getOrderId()+" ");
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql.toString());
		return (query.executeUpdate() > 0);
	}

	@Override
	public boolean updateSendStatus(Long ids) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer(
				"update OrderInfo s set s.sendStatus=4,s.payStatus = 1 where s.orderId ="+ids);
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql.toString());
		return (query.executeUpdate() > 0);
		
	}

	

}
